package com.relife.sys.service;

import com.relife.common.utils.ReflectUtil;
import com.relife.common.utils.StringUtil;
import com.relife.core.entity.FunctionEntity;
import com.relife.core.service.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;



@Service
@Transactional
public class FunctionService extends BaseService {

	public void saveFunction(FunctionEntity fun) {
		if (fun.getParent() == null || StringUtil.isEmpty(fun.getParent().getId())) {
			fun.setParent(null);
		}
		if (StringUtil.isEmpty(fun.getId())) {
			this.save(fun);
		} else {
			FunctionEntity t = this.get(FunctionEntity.class, fun.getId());
			ReflectUtil.copyNotNullPro2Bean(fun, t);
		}
	}

	/**
	 * 
	 * @author WU
	 * @date 2016年8月24日 上午10:26:13
	 * @param fun
	 */
	public void delFunction(FunctionEntity fun) {
		this.delete(get(FunctionEntity.class, fun.getId()));
	}
}
